
<template>
  <div>

    <a-select
        ref="select"
        v-model:value="lostType"
        style="width: 120px"
        @focus="focus"
        @change="handleChange"
    >
      <a-select-option value="">全部</a-select-option>
      <a-select-option value="招领">招领</a-select-option>
      <a-select-option value="寻物" >寻物</a-select-option>
    </a-select>

    <a-table :columns="columns" :data-source="data">



    <span slot="action" slot-scope="text, record">

    <a @click="updateMessage(record.lostId)">管理评论</a>


    </span>

    </a-table>

    <a-modal width="1000px" v-model:visible="visible" title="管理评论"  @ok="handleOk">

      <a-table :columns="messageColumns" :data-source="messageData">

          <span slot="action" slot-scope="text, record">

      <a-popconfirm
          title="您确定要删除当前评论?"
          ok-text="Yes"
          cancel-text="No"
          @confirm="deleteMessage(record.messageId)"
          @cancel="()=>{}"
      >
    <a>删除评论</a>
  </a-popconfirm>

    </span>
      </a-table>
    </a-modal>


  </div>

</template>

<script>
import { message } from 'ant-design-vue';
const columns = [
  {
    title: '标题',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '内容',
    dataIndex: 'text',
    key: 'text',
  },
  {
    title: '发布者',
    dataIndex: 'creatUserName',
    key: 'creatUserName',
  },
  {
    title: '发布时间',
    key: 'createTime',
    dataIndex: 'createTime',
  },
  {
    title: '发布类型',
    key: 'lostType',
    dataIndex: 'lostType',
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];

const messageColumns = [
  {
    title: '发布者',
    dataIndex: 'sentUserName',
    key: 'sentUserName',
  },
  {
    title: '发布时间',
    key: 'sendTime',
    dataIndex: 'sendTime',
  },
  {
    title: '发布内容',
    key: 'message',
    dataIndex: 'message',
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];


/**
 * 这是物品管理
 */
export default ({
  data() {
    return {
      data:[],
      columns,
      lostType:"全部",
      visible:false,
      messageData:[],
      messageColumns,
      messageId:-1,
    }
  },
  beforeCreate() {

    this.$http({
      method: 'post',
      url: 'http://localhost:18082/loatandfound/list',
      data: {
        typeValue:this.lostType
      },
      headers:{
        user:localStorage.getItem("user"),
      }
    }).then((e)=>{

      if(e.data.status){

        this.data=e.data.data;


      }

    })


  },
  mounted() {

  },
  methods: {
    handleOk(){
      this.visible=false;
    },
    deleteMessage(e1){

      this.$http({
        method: 'delete',
        url: 'http://localhost:18082/loatandfound/deletemessage',
        data: {
          messageId:e1
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{

        if(e.data.status==true){
          message.info("删除成功！",3);

          this.$http({
            method: 'get',
            url: 'http://localhost:18082/loatandfound/messagelist',
            params: {
              lostId:this.messageId
            },
            headers:{
              user:localStorage.getItem("user"),
            }
          }).then((e)=>{
            if(e.data.status){
              this.messageData=e.data.data.messages;

            }
          })


        }else{
          message.error("删除失败！",3);
        }
      })

    },
    updateMessage(e){
      this.visible=true;
      this.messageId=e;
      this.$http({
        method: 'get',
        url: 'http://localhost:18082/loatandfound/messagelist',
        params: {
          lostId:e
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{
        if(e.data.status){
          this.messageData=e.data.data.messages;

        }
      })

    },

    focus(){},
    handleChange(){

      this.$http({
        method: 'post',
        url: 'http://localhost:18082/loatandfound/list',
        data: {
          text:"",
          title:"",
          dateS:[],
          tagS:[],
          typeValue:this.lostType
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{

        if(e.data.status){

          this.data=e.data.data;


        }

      })

    }
  },
})

</script>

